<template>
  <div>
    <el-row>
      <el-col class="select">
        <el-select v-model="selectYear" placeholder="请选择" size="mini" @change="handleChange">
          <el-option
            v-for="item in years"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
        <el-select v-model="selectMonth" placeholder="请选择" size="mini" @change="handleChange">
          <el-option
            v-for="item in 12"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-col>
    </el-row>
    <el-calendar v-model="date">
      <template
        #dateCell="{date, data}"
      >
        <div>
          <span :class="data.isSelected ? 'is-selected' : ''">
            {{ data.day.split('-')[2] }}
          </span>
          <span v-if="isWeek(date)" class="text">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  name: 'WorkDate',
  data() {
    return {
      selectYear: new Date().getFullYear(),
      years: [],
      selectMonth: new Date().getMonth() + 1,
      date: new Date()
    }
  },
  created() {
    // Array(11).fill(' ').map((item, index) => 2021 - 5 + index)
    this.years = Array.from(Array(11), (item, index) => this.selectYear - 5 + index)
  },
  methods: {
    isWeek(date) {
      return date.getDay() === 6 || date.getDay() === 0
    },
    handleChange() {
      const date = this.selectYear + '-' + this.selectMonth
      this.date = new Date(date)
    }
  }

}
</script>

<style scoped lang='scss'>
.select {
  display: flex;
  justify-content: flex-end;

  .el-select {
    width: 80px;
  }

}

::v-deep .el-calendar-day {
  height: auto;
  text-align: center;
  line-height: 30px;
}

::v-deep .el-calendar-table__row td, ::v-deep .el-calendar-table tr td:first-child, ::v-deep .el-calendar-table__row td.prev {
  border: none;
}

.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}

.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}

.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;

}

::v-deep thead {
  th {
    font-size: 14px;
    font-weight: bold;
  }
}

::v-deep .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}

::v-deep .el-calendar__header {
  display: none
}

.text {
  font-size: 12px;
  color: #fff;
  background: #fa7c4d;
  width: 20px;
  height: 20px;
  border-radius: 20px;
  display: inline-block;
  line-height: 20px;
  text-align: center;
}
</style>
